package com.edou.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.edou.base.page.PageResult;
import com.edou.system.dao.ISysDictItemDao;
import com.edou.system.dto.SysDictItemCondition;
import com.edou.system.entity.SysDictItem;
import com.edou.system.service.ISysDictItemService;

@Service("sysDictItemServiceImpl")
@Transactional("transactionManager")
public class SysDictItemServiceImpl implements ISysDictItemService {
	
	@Resource(name = "sysDictItemDaoImpl")
	private ISysDictItemDao sysDictItemDao;
	
	/**
	 * 分页查询
	 * @param pageResult 分页对象
	 * @param condition 查询条件类
	 */
	public void listDictItemByPage(PageResult<SysDictItem> pageResult, SysDictItemCondition condition){
		
		int rows = sysDictItemDao.listDictItemByPageCount(condition);
		pageResult.setRows(rows);

		RowBounds rowBounds = new RowBounds(pageResult.getCurrentPageIndex(),pageResult.getPageSize());
		List<SysDictItem> list = sysDictItemDao.listDictItemByPage(rowBounds,condition);
		
		pageResult.setResult(list);
	}
	
	@Override
	public List<SysDictItem> listSysDictItemByDictId(Long dictId) {
		return sysDictItemDao.listSysDictItemByDictId(dictId);
	}
	
	@Override
	public void add(SysDictItem item) {
		sysDictItemDao.add(item);
	}
	
	@Override
	public void update(SysDictItem item) {
		sysDictItemDao.update(item);
	}
	

	@Override
	public SysDictItem getSysDictItemById(Long id) {
		return sysDictItemDao.getSysDictItemById(id);
	}

	@Override
	public void delByIds(Long[] ids) {
		sysDictItemDao.delByIds(ids);
	}

	/**
	 * 根据数据库code查询明细
	 * @param code
	 * @return
	 */
	public List<SysDictItem> listSysDictItemByCode(String code) {
		return sysDictItemDao.listSysDictItemByCode(code);
	}
}
